<% circles_addresses_list = CustomContractsHelper.get_custom_addresses_list(:circles_addresses) %>
<% address_hash_str = "0x" <> Base.encode16(@token.contract_address_hash.bytes, case: :lower) %>
<% {:ok, created_from_address} = if @token.contract_address_hash, do: Chain.hash_to_address(@token.contract_address_hash), else: {:ok, nil} %>
<% created_from_address_hash = if from_address_hash(created_from_address), do: "0x" <> Base.encode16(from_address_hash(created_from_address).bytes, case: :lower), else: nil %>
<section class="address-overview" data-page="token-details" data-page-address-hash="<%= @token.contract_address_hash %>">
  <%= render BlockScoutWeb.Advertisement.TextAdView, "index.html", conn: @conn %>
  <div class="row js-ad-dependant-mb-2 js-ad-dependant-mb-5-reverse">
    <div class="col-md-12 js-ad-dependant-mb-2">
      <div class="card js-ad-dependant-mb-2">
        <div class="card-body fs-14" style="line-height: 31px;" token-page data-async-counters="<%= @counters_path %>">
          <h1 class="card-title d-flex" style="justify-content: space-between; margin-bottom: 0.75rem">
            <div style="line-height: 30px;">
              <%= cond do %>
                <% Enum.member?(circles_addresses_list, address_hash_str) -> %>
                  <div class="custom-dapp-header-container">
                    <img class="custom-address-icon"/>
                  </div>
                <% Enum.member?(circles_addresses_list, created_from_address_hash) -> %>
                  <div class="custom-dapp-header-container">
                    <img class="custom-address-icon"/>
                  </div>
                <% true -> %>
                  <%= nil %>
              <% end %>
              <%= if token_name?(@token) do %>
                  <span
                    id="token-icon"
                    data-chain-id="<%= Application.get_env(:block_scout_web, :chain_id) %>"
                    data-address-hash="<%= Address.checksum(@token.contract_address_hash) %>"
                    data-display-token-icons="<%= Application.get_env(:block_scout_web, :display_token_icons) %>">
                  </span>
                  <div class="title-with-label"><%= @token.name %></div>
              <% else %>
                <%= gettext("Token Details") %>
              <% end %>
              <%= render BlockScoutWeb.AddressView, "_labels.html", address_hash: @token.contract_address_hash, tags: @tags %>
            </div>
            <!-- buttons -->
            <span class="overview-title-buttons token float-right">
              <%= render BlockScoutWeb.CommonComponentsView, "_btn_copy.html",
                  additional_classes: ["overview-title-item"],
                  clipboard_text: Address.checksum(@token.contract_address_hash),
                  aria_label: gettext("Copy Address"),
                  title: gettext("Copy Address") %>
              <%= render BlockScoutWeb.CommonComponentsView, "_btn_qr_code.html" %>
            </span>
          </h1>
          <dl class="row mt-4">
            <dt class="col-sm-4 col-md-4 col-lg-3 text-muted">
              <%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html",
              text: gettext("Address of the token contract") %>
              <%= gettext("Contract") %>
            </dt>
            <dd class="col-sm-8 col-md-8 col-lg-9 contract-address">
              <%= link(
                  @token.contract_address_hash,
                  to: AccessHelper.get_path(@conn, :address_path, :show, 
                  Address.checksum(@token.contract_address_hash)),
                  "data-test": "token_contract_address"
                  ) 
              %>
            </dd>
          </dl>
          <dl class="row <%= if !total_supply?(@token), do: "d-none" %>" data-selector="total-supply-row">
            <dt class="col-sm-4 col-md-4 col-lg-3 text-muted">
              <%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html",
              text: gettext("The total amount of tokens issued") %>
              <%= gettext("Total supply") %>
            </dt>
            <dd class="col-sm-8 col-md-8 col-lg-9" data-selector="total-supply-value" data-token-symbol="<%= @token.symbol %>">
              <%= if total_supply?(@token) do %>
                <%= if decimals?(@token) do %>
                  <%= format_according_to_decimals(@token.total_supply, @token.decimals) %>
                <% else %>
                  <%= format_integer_to_currency(@token.total_supply) %>
                <% end %> <%= @token.symbol %>
              <% end %>
            </dd>
          </dl>
          <%= if @token.total_supply && @token.fiat_value do %>
            <dl class="row">
              <dt class="col-sm-4 col-md-4 col-lg-3 text-muted">
                <%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html",
                text: gettext("Total Supply * Price") %>
                <%= gettext("Market Cap") %>
              </dt>
              <dd class="col-sm-8 col-md-8 col-lg-9">
                <span data-selector="token-supply-usd" data-usd-value="<%= total_supply_usd(@token) %>"></span>
              </dd>
            </dl>
            <%= unless Map.has_key?(@token, :custom_cap) && @token.custom_cap do %>
              <dl class="row">
                <dt class="col-sm-4 col-md-4 col-lg-3 text-muted">
                  <%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html",
                  text: gettext("Price per token on the exchanges") %>
                  <%= gettext("Price") %>
                </dt>
                <dd class="col-sm-8 col-md-8 col-lg-9">
                  <span data-selector="token-price" data-usd-value="<%= @token.fiat_value %>"></span>
                </dd>
              </dl>
            <% end %>  
          <% end %>
          <dl class="row">
            <dt class="col-sm-4 col-md-4 col-lg-3 text-muted">
              <%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html",
              text: gettext("Number of accounts holding the token") %>
              <%= gettext("Holders") %>
            </dt>
            <dd class="col-sm-8 col-md-8 col-lg-9">
              <% link = if @conn.request_path |> String.contains?("/token-holders"), do: "", else: AccessHelper.get_path(@conn, :token_holder_path, :index, @token.contract_address_hash) %>
              <a href="<%= link %>#holders" class="page-link bs-label large btn-no-border-link-to-tems" token-holder-count><%= render BlockScoutWeb.CommonComponentsView, "_loading_spinner.html", loading_text: gettext("Fetching holders...") %></a>
            </dd>
          </dl>
          <dl class="row">
            <dt class="col-sm-4 col-md-4 col-lg-3 text-muted">
              <%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html",
              text: gettext("Number of transfers for the token") %>
              <%= gettext("Transfers") %>
            </dt>
            <dd class="col-sm-8 col-md-8 col-lg-9">
              <% link = if @conn.request_path |> String.contains?("/token-transfers"), do: "", else: AccessHelper.get_path(@conn, :token_transfer_path, :index, @token.contract_address_hash) %>
              <a href="<%= link %>#transfers" class="page-link bs-label large btn-no-border-link-to-tems" token-transfer-count><%= render BlockScoutWeb.CommonComponentsView, "_loading_spinner.html", loading_text: gettext("Fetching transfers...") %></a>
            </dd>
          </dl>
          <%= if decimals?(@token) do %>
            <dl class="row">
              <dt class="col-sm-4 col-md-4 col-lg-3 text-muted">
                <%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html",
                text: gettext("Number of digits that come after the decimal place when displaying token value") %>
                <%= gettext("Decimals") %>
              </dt>
              <dd class="col-sm-8 col-md-8 col-lg-9">
                <%= @token.decimals %>
              </dd>
            </dl>
          <% end %>  
          <dl class="row">
            <dt class="col-sm-4 col-md-4 col-lg-3 text-muted">
              <%= render BlockScoutWeb.CommonComponentsView, "_i_tooltip_2.html",
              text: gettext("Type of the token standard") %>
              <%= gettext("Token type") %>
            </dt>
            <dd class="col-sm-8 col-md-8 col-lg-9">
              <%= @token.type %>
            </dd>
          </dl>
        </div>
      </div>
    </div>
  </div>
</section>
<!-- Modal QR -->
<%= render BlockScoutWeb.CommonComponentsView, "_modal_qr_code.html", qr_code: BlockScoutWeb.AddressView.qr_code(Address.checksum(@token.contract_address_hash)), title: @token.contract_address %>
<%= render BlockScoutWeb.Advertisement.BannersAdView, "_banner_728.html", conn: @conn %>
<script defer data-cfasync="false" src="<%= static_path(@conn, "/js/token-overview.js") %>"></script>
